local zhuwei = fk.CreateSkill {
  name = "lvshi__zhuwei",
}

Fk:loadTranslationTable{
  ["lvshi__zhuwei"] = "筑围",
  ["@lvshi__zhuwei-turn"] = "筑围",
  [":lvshi__zhuwei"] = "你使用的实体牌结算完毕后，若无角色处于濒死状态，你可视为使用【调虎离山】，若这两张牌的目标为同一名角色，你再视为使用【援护】。",
  ["#lvshi__zhuwei-use"] = "筑围：你可视为使用【调虎离山】",
  ["$lvshi__zhuwei1"] = "恪守成规，则敌无可攻。",
  ["$lvshi__zhuwei2"] = "善守者，敌不知其所攻。",
}

local U = require "packages/utility/utility"

zhuwei:addEffect(fk.CardUseFinished, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhuwei.name) and U.isPureCard(data.card) and table.every(player.room.alive_players, function(p)
      return not p.dying
    end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local use = room:askToUseVirtualCard(player, {
      name = "lvshi__lure_tiger",
      skill_name = zhuwei.name,
      prompt = "#lvshi__zhuwei-use",
      cancelable = true,
      skip = true,
      --[[card_filter = {
        n = 1,
        cards = player:getCardIds("he"),
      },]]
    })
    if use then
      event:setCostData(self, use)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:useCard(event:getCostData(self))
    if #data.tos == 1 and data.tos[1] == event:getCostData(self).tos[1] then
      --player:addToPile("shield", room:getNCards(1), false, zhuwei.name)
      room:askToUseVirtualCard(player, {
        name = "lvshi__support",
        skill_name = zhuwei.name,
        cancelable = false,
      })
    end
  end,
})

return zhuwei
